package com.zhao.modleclass.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.zhao.modleclass.R;
import com.zhao.modleclass.activity.HPType1Activity;
import com.zhao.modleclass.activity.Live_Fragment_Activity;
import com.zhao.modleclass.bean.HomePageBean;

import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */

public class HP_NewAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<HomePageBean.DataBean> homePageBean;
    private LayoutInflater inflater;
    private RecyclerView recyclerView;
    private Intent intent;

    public HP_NewAdapter(Context context, List<HomePageBean.DataBean> homePageBean, RecyclerView recyclerView) {
        this.context = context;
        this.homePageBean = homePageBean;
        this.recyclerView = recyclerView;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_hp_selected, parent, false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = recyclerView.getChildAdapterPosition(v);
                if (homePageBean.get(position).getLiveType() == 4) {
                    intent = new Intent(context, Live_Fragment_Activity.class);
                    intent.putExtra("CourseId",homePageBean.get(position).getCourseId());

                    context.startActivity(intent);
                } else if (homePageBean.get(position).getLiveType() == 3){
                    intent = new Intent(context, HPType1Activity.class);
                    intent.putExtra("Type",3);
                    intent.putExtra("title",homePageBean.get(position).getTitle());
                    intent.putExtra("imag_URL",homePageBean.get(position).getImageUrl());
                    intent.putExtra("CourseId",homePageBean.get(position).getCourseId());
                    context.startActivity(intent);
                }
            }
        });
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder) {
            Glide.with(context).load(homePageBean.get(position).getImageUrl()).into(((MyViewHolder) holder).item_hp_img);
            ((MyViewHolder) holder).item_selected_liveTime.setText(homePageBean.get(position).getLiveTime() + "");
            ((MyViewHolder) holder).item_selected_techJobName.setText(homePageBean.get(position).getTechJobName());
            ((MyViewHolder) holder).item_selected_techNickName.setText(homePageBean.get(position).getTechNickName());
            ((MyViewHolder) holder).item_selected_title.setText(homePageBean.get(position).getTitle());
        }
    }

    @Override
    public int getItemCount() {
        return homePageBean.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView item_hp_img;
        private TextView item_selected_title, item_selected_techNickName, item_selected_techJobName, item_selected_liveTime;

        public MyViewHolder(View itemView) {
            super(itemView);
            item_hp_img = (ImageView) itemView.findViewById(R.id.item_hp_img);
            item_selected_title = (TextView) itemView.findViewById(R.id.item_selected_title);
            item_selected_techNickName = (TextView) itemView.findViewById(R.id.item_selected_techNickName);
            item_selected_techJobName = (TextView) itemView.findViewById(R.id.item_selected_techJobName);
            item_selected_liveTime = (TextView) itemView.findViewById(R.id.item_selected_liveTime);
        }
    }
}
